package com.gavin.algorithm.sort;

import java.util.Arrays;

/**
 * 简单选择排序
 * 
 * @author lenovo
 *
 */
public class SelectSort {

	public static void main(String[] args) {
		int[] a = { 26, 53, 67, 48, 57, 13, 48, 32, 60, 50 };
		selectSort(a);
		System.out.println(Arrays.toString(a));
	}

	private static void selectSort(int[] array) {

		int i, j, min, temp,count1=0,count2=0;
		for (i = 0; i < array.length - 1; i++) {
			min = i;
			for (j = i + 1; j < array.length; j++) {
				count1++;
				if (array[min] > array[j]) {
					min = j;
				}
			}

			if (min != i) {
				count2++;
				temp = array[i];
				array[i] = array[min];
				array[min] = temp;
			}
		}
		
		System.out.println("总共进行了"+count1+"次比较,"+count2+"次交换");
	}

}
